
#######################
# Creating Main graph #
#######################

## Load packages ##
library(readxl)
library(ggplot2) 
library(tidyverse)

## Read data ## 

# Country-level characteristics #
R_import_cntry <- read_excel("[paste path]/Country level.xlsx")
R_import_cntry_ord <- R_import_cntry %>%
  mutate(Group = factor(Group, levels = rev(Group))) 
R_import_cntry_ord$type <- ifelse(R_import_cntry_ord$Group == "Global", "Global", "Other")

# Remove CI for global because narrower than diamond itself
R_import_cntry_ord$LCL[R_import_cntry_ord$Group == "Global"] <- NA
R_import_cntry_ord$UCL[R_import_cntry_ord$Group == "Global"] <- NA

# Individual-level characteristics #
R_import_ind <- read_excel("[paste path]/Individual level.xlsx")
R_import_ind_ord <- R_import_ind %>%
  mutate(Group = factor(Group, levels = rev(Group))) 

## Create forest plot: Country-level characteristics ##

forest_plot_cntry <- ggplot(R_import_cntry_ord, aes(y = Group, x = prevalence)) +
  geom_errorbarh(aes(xmin = LCL, xmax = UCL), height = 0.2, color = "gray50") +
  geom_point(aes(size = type, color = type, shape = type)) +
  labs(x = "Weighted % (95%-CI)", y = "") +
  theme_classic() +
  scale_shape_manual(values = c("Global" = 18, "Other" = 16), guide = "none") +
  scale_size_manual(values = c("Global" = 2.5, "Other" = 2), guide = "none") +
  scale_color_manual(values = c("Global" = "lightblue4", "Other" = "#304E55"), guide = "none") +
  theme(text = element_text(family = "serif")) +
  theme(axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        axis.text.x = element_text(size = 11, color="black"),
        axis.title.x = element_text(size = 11, margin = margin(t = 7)),
        axis.line.x = element_line(linewidth=0.3),
        axis.line.y = element_line(linewidth=0.3)) + 
  scale_y_discrete(limits = rev(R_import_cntry_ord$Group)) +
  scale_x_continuous(limits = c(0, 100), breaks = seq(0, 100, by = 20), expand = expansion(add = c(0, 2))) 

ggsave("Forest plot A.pdf", plot = forest_plot_cntry, width = 3, height = 4.5)

## Create forest plot: Individual-level characteristics ##

forest_plot_ind <- ggplot(R_import_ind_ord, aes(y = Group, x = prevalence)) +
  geom_errorbarh(aes(xmin = LCL, xmax = UCL), height = 0.2, color = "gray50") +
  geom_point(size = 1.6, color = "#304E55") +
  labs(x = "Weighted % (95%-CI)", y = "") +
  theme_classic() +
  theme(text = element_text(family = "serif")) +
  theme(axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        axis.text.x = element_text(size = 11, color="black"),
        axis.title.x = element_text(size = 11, margin = margin(t = 7)),
        axis.line.x = element_line(linewidth=0.3),
        axis.line.y = element_line(linewidth=0.3)) + 
  scale_y_discrete(limits = rev(R_import_ind_ord$Group)) +
  scale_x_continuous(limits = c(0, 100), breaks = seq(0, 100, by = 20), expand = expansion(add = c(0, 2))) 

ggsave("Forest plot B.pdf", plot = forest_plot_ind, width = 3, height = 5.6)





